package io;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Author: ycy
 * @CreateDate: 2019/7/17 12:42
 */
public class downkorea {

  public static final Gson gson = new GsonBuilder().create();

  public static void main(String[] args) throws IOException {

    List<String> citys = FileUtils.readLines(new File("D:\\Users\\yincy\\Desktop\\搜索引擎\\下线需求\\韩国朝鲜城市cityid.txt"), "UTF-8");
    List<String> cityFilters = Lists.newArrayList();
    for (String city : citys) {
      cityFilters.add(city.trim());
    }

    //加载韩国和朝鲜城市


    //
    List<String> lineidwords = FileUtils.readLines(new File("D:\\Users\\yincy\\Desktop\\搜索引擎\\下线需求\\sql_download_data_201907171239.txt"), "UTF-8");
    Map<String, UrlInfo> wordLineIdMap = Maps.newHashMap();
    for (String lineidword : lineidwords) {
      String[] split = lineidword.split("\\|");
      String trim = split[2].trim();
      UrlInfo urlInfo1 = gson.fromJson(trim, UrlInfo.class);
      wordLineIdMap.put(split[0].trim(), urlInfo1);
    }

    for (Map.Entry<String, UrlInfo> entry : wordLineIdMap.entrySet()) {
      String key = entry.getKey();//word
      UrlInfo value = entry.getValue();//id
//      for (String cityFilter : cityFilters) {
//        if (key.indexOf(cityFilter) > 0) {
//          System.out.println(" " + value);
//          break;
//        }
//      }
      if (cityFilters.contains(String.valueOf(value.arrivalCityId)) || cityFilters.contains(String.valueOf(value.startCityId))) {
        System.out.println(key + " " + value);
      }
    }


  }

  class UrlInfo {

    int arrivalCityId;
    int startCityId;

  }


}
